import logging

from model.Config import Config
from operators.SummissionApi import getAccessToken, updateAppFileInfo
from utils.FileUtil import processExcel


def getBaseSetting():
    userConig = Config().getUserConfig()
    runConfig = Config().getRunConfig()
    if userConig["user_name"] == "" or userConig["user_password"] == "":
        logging.error("请在Config/config.json中设置账户和密码")
        return None
    if userConig["client_id"] == "" or userConig["client_secret"] == "":
        logging.error("请在Config/config.json中设置client_id和client_secret")
        return None
    try:
        appInfos = processExcel()
    except Exception:
        logging.error("请确认config/appInfos.xlsx文件存在")
        return None

    return appInfos, userConig, runConfig

def main():
    appInfos, userConfig, runConfig = getBaseSetting()
    if userConfig["access_token"] == "":
        getAccessToken(userConfig)
        return
    for appInfo in appInfos:
        updateAppFileInfo(userConfig, appInfo)




if __name__ == "__main__":
    main()